Modulus(%) is a number that remains when you divide something by a number.
So, if you do 2 % 2, the answer would be 0 since there is no remainder.
EX.
2 % 1 = 0 --> 1 goes into 2 perfectly with no remainder so it return 0 2 % 3 = 2 --> 3 does not go into 2 at all, so it just returns 2 5 % 2 = 1 --> 2 goes into 5 two times, and gives remainder of 1, so it returns 1 6 % 4 = 2 --> 4 goes into 6 once, and gives remainder of 2, so it returns 2
Division( / ) is the same method that we use in math except that in computer science, it's necessary
to distinguish between a double and a integer. Double is a number with a decimal point. Int (integer) is a number with no decimal point.
If you divide an int by an int, the answer would be an int.
If you divide an int by a double, the answer would be a double.
If you divide a double by an int, the answer would be a double.
If you divide a double by a double, the answer would be a double. (These only apply when the numbers don't divide up perfectly.)
If the two numbers you are dividing are both integers, the answer would always be an int.
import objectdraw.*;
public class number extends FrameWindowController
{
private int x;
private double y;
public void begin()
{
x = 2; //Because the variable is already set as a int,
//You can not put a double number here. It cause an error (loss of precision).
y = 1.2;
System.out.println(y/x); //This would print out the result of
// 2 / 1.2 which will be 0.6
}
}
So, if you do 2 % 2, the answer would be 0 since there is no remainder.
EX.
2 % 1 = 0 --> 1 goes into 2 perfectly with no remainder so it return 0
2 % 3 = 2 --> 3 does not go into 2 at all, so it just returns 2
5 % 2 = 1 --> 2 goes into 5 two times, and gives remainder of 1, so it returns 1
6 % 4 = 2 --> 4 goes into 6 once, and gives remainder of 2, so it returns 2
Division( / ) is the same method that we use in math except that in computer science, it's necessary
to distinguish between a double and a integer.
Double is a number with a decimal point.
Int (integer) is a number with no decimal point.
If you divide an int by an int, the answer would be an int.
If you divide an int by a double, the answer would be a double.
If you divide a double by an int, the answer would be a double.
If you divide a double by a double, the answer would be a double. (These only apply when the numbers don't divide up perfectly.)
If the two numbers you are dividing are both integers, the answer would always be an int.
import objectdraw.*; public class number extends FrameWindowController { private int x; private double y; public void begin() { x = 2; //Because the variable is already set as a int, //You can not put a double number here. It cause an error (loss of precision). y = 1.2; System.out.println(y/x); //This would print out the result of // 2 / 1.2 which will be 0.6 } }